home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_exmh.idb / usr / freeware / lib / exmh-2.5 / pick.tcl.z / pick.tcl
Text File  |  2002-07-08  |  6KB  |  218 lines

  1. # pick.tcl
  2. #
  3. # Interface to MH pick functionality
  4. #
  5. # Copyright (c) 1993 Xerox Corporation.
  6. # Use and copying of this software and preparation of derivative works based
  7. # upon this software are permitted. Any distribution of this software or
  8. # derivative works must comply with all applicable United States export
  9. # control laws. This software is made available AS IS, and Xerox Corporation
  10. # makes no warranty about the software, its performance or its conformity to
  11. # any specification.
  12.  
  13. proc Pick {} {
  14.     if [Exwin_Toplevel .pick "Pick Messages" Pick] {
  15.     set t .pick
  16.     set f .pick.but
  17.  
  18.     .pick.but.quit configure -command {Exwin_Dismiss .pick nosize}
  19.     Widget_AddBut $f clear "Clear" { PickClear }
  20.     Widget_AddBut $f mark "Mark Seen" {PickMarkSeen}
  21.     Widget_AddBut $f pick "Pick" {Pick_It} {left padx 1 filly}
  22.     Widget_CheckBut $f add "Add to Sel" pick(addtosel) {left padx 1 filly}
  23.     Widget_AddBut $f project "New FTOC" Ftoc_NewFtoc {left padx 1 filly}
  24.  
  25.     PickSetup
  26.         Widget_AddBut .pick or "-Or-" PickOr {bottom pady 5 filly}
  27.     }
  28. }
  29. proc PickClear {} {
  30.     global pick
  31.     for {set pane 0} {$pane <= $pick(panes)} {incr pane} {
  32.     destroy .pick.rim$pane
  33.     }
  34.     PickSetup
  35. }
  36. proc PickSetup {} {
  37.     global pick
  38.  
  39.     catch {unset pick}
  40.     set pick(panes) 0
  41.     set pick(addtosel) 0
  42.     set pick(fields) {subject from to cc tocc before after search component}
  43.  
  44.     set f [Widget_Frame .pick rim0 Rim]
  45.     Widget_BeginEntries 20 25 Pick_It
  46.     Widget_LabeledEntry $f.sequence    "Add to Sequence(s)" pick(sequence)
  47.     set pick(sequence) ""
  48.     Widget_LabeledEntry $f.msgs        "Pick from Seq/msg(s)" pick(msgs)
  49.     set pick(msgs) all
  50.     set pad [Widget_Frame $f pad Pad]
  51.     $pad configure -height 10 -width 10
  52.     set pick(0,lastentry) [Widget_EndEntries]        ;# This sets focus
  53.  
  54.     PickNewPane
  55. }
  56. proc PickOr {} {
  57.     global pick
  58.  
  59.     Widget_Label .pick.rim$pick(panes) or {fill bottom} -text "- Or -"
  60.     PickNewPane
  61. }
  62. proc PickNewPane {} {
  63.     global pick
  64.  
  65.     set f [Widget_Frame .pick rim[incr pick(panes)] Rim]
  66.     $f configure -bd 5
  67.  
  68.     set menu [Widget_AddMenuB $f fields "Choose pick attribute" {top}]
  69.     foreach who $pick(fields) {
  70.     Widget_AddMenuItem $menu $who [list PickAddField $f $pick(panes) $who]
  71.     }
  72. }
  73. proc PickAddField {f pane what} {
  74.     global pick
  75.  
  76.     if ![info exists pick($pane,$what,and)] {
  77.     set pick($pane,$what,and) 0
  78.     }
  79.     set iter [incr pick($pane,$what,and)]
  80.     set who $what$iter
  81.     set pick($pane,$who,or) 1
  82.  
  83.     lappend pick($pane,fields) [list $what $iter]
  84.  
  85.     # Find last entry for linking focus
  86.     for {set rim $pane} {$rim >=0} {incr rim -1} {
  87.     if [info exists pick($rim,lastentry)] {
  88.         set last $pick($rim,lastentry)
  89.         break
  90.     }
  91.     }
  92.     Widget_BeginEntries 10 25 Pick_It $last
  93.  
  94.     set l [string toupper [string index $what 0]][string range $what 1 end]
  95.     if [string match component $what] {
  96.     Widget_EntryEntry $f.$who pick($pane,$who,component) pick($pane,$who,1)
  97.     } else {
  98.     Widget_LabeledEntry $f.$who $l pick($pane,$who,1)
  99.     }
  100.  
  101.     set b [Widget_CheckBut $f.$who not "Not" pick($pane,$who,not)]
  102.     $b config -padx 0 -pady 0
  103.     pack forget $f.$who.not
  104.     pack $f.$who.not -before $f.$who.label -side left
  105.  
  106.     set b [Widget_AddBut $f.$who or "Or" [list PickAddOrField $pane $who] \
  107.     {left padx 10 fill}]
  108.     $b config -padx 0 -pady 0
  109.  
  110.     set pick($pane,lastentry) [Widget_EndEntries]
  111.     focus $pick($pane,lastentry)
  112. }
  113. proc PickAddOrField {pane who} {
  114.     global pick
  115.  
  116.     set or [incr pick($pane,$who,or)]
  117.     set f .pick.rim$pane.$who
  118.     Widget_LabeledEntryOr $f $or pick($pane,$who,$or)
  119.     set me $f.entry$or
  120.     if {$or == 2} {
  121.     set lcheck $f.entry
  122.     } else {
  123.     set lcheck $f.entry[expr $or -1]
  124.     }
  125.     if {$pick($pane,lastentry) == $lcheck} {
  126.     set pick($pane,lastentry) $me
  127.     }
  128. }
  129. proc Pick_It {} {
  130.     global pick exmh
  131.     set cmd [list exec pick +$exmh(folder) -list]
  132.     set inpane 0
  133.     set hadpane 0
  134.     for {set pane 1} {$pane <= $pick(panes)} {incr pane} {
  135.     set and 0
  136.     if ![info exists pick($pane,fields)] continue
  137.     foreach l $pick($pane,fields) {
  138.         set field [lindex $l 0]
  139.         set iter [lindex $l 1]
  140.         set who $field$iter
  141.         set or 0
  142.         for {set i 1} {$i <= $pick($pane,$who,or)} {incr i} {
  143.         set text [string trim $pick($pane,$who,$i)]
  144.         if {[string length $text] == 0} continue
  145.  
  146.         if {$inpane != $pane} {
  147.             if $hadpane {lappend cmd -or}
  148.             lappend cmd -lbrace
  149.             set inpane $pane
  150.             set hadpane 1
  151.         } elseif $and {
  152.             lappend cmd -and
  153.             set and 0
  154.         } elseif $or {
  155.             lappend cmd -or
  156.         }
  157.         if !$or {
  158.             if $pick($pane,$who,not) {
  159.                 lappend cmd -not
  160.             }
  161.             lappend cmd -lbrace
  162.         }
  163.         switch -exact $field \
  164.         component {lappend cmd --$pick($pane,$who,component) $text} \
  165.         tocc      {lappend cmd -lbrace -to $text -or -cc $text -rbrace} \
  166.         default   {lappend cmd -$field $text}
  167.             set or 1
  168.         }
  169.         if $or {
  170.         lappend cmd -rbrace
  171.         }
  172.         set and 1
  173.     }
  174.     if {$inpane == $pane} {lappend cmd -rbrace}
  175.     }
  176.     set msgs $pick(msgs)
  177.     foreach s $pick(sequence) {
  178.     lappend msgs -sequence $s
  179.     }
  180.  
  181.     Exmh_Debug Pick_It $cmd $msgs
  182.     busy PickInner $cmd $msgs
  183.     Exmh_Focus
  184. }
  185. proc PickInner {cmd msgs} {
  186.     global pick
  187.     Exmh_Status "$cmd $msgs" red
  188.     if [catch [concat $cmd $msgs] ids] {
  189.     Exmh_Status "Fail: [string range $ids 2 end]" purple
  190.     return
  191.     }
  192.     set pick(ids) [split $ids \n]
  193.     Exmh_Debug Ftoc_PickMsgs $pick(ids)
  194.     if {! $pick(addtosel)} {
  195.     Ftoc_RangeUnHighlight
  196.     }
  197.     Ftoc_PickMsgs $pick(ids) $pick(addtosel)
  198.     Exmh_Status "Pick hit [llength $pick(ids)] msgs" blue
  199. }
  200. proc PickMarkSeen {} {
  201.     global exmh pick
  202.     if ![info exists pick(ids)] {
  203.     return
  204.     }
  205.     Mh_MarkSeen $exmh(folder) $pick(ids)
  206.     Ftoc_MarkSeen $pick(ids)
  207.     foreach id $pick(ids) {
  208.     Flist_MsgSeen $id
  209.     }
  210. }
  211. proc Pick_MarkSeen {} {
  212.     global exmh pick
  213.     Exmh_Status "Clearing unseen sequence..." red
  214.     set pick(ids) [Mh_Unseen $exmh(folder)]
  215.     busy PickMarkSeen
  216.     Exmh_Status ok blue
  217. }
  218.